Skip to content

Allow choice of binding category and renaming of bindings in specific categories (e.g., functions)#1319

Merged
jorisdral merged 8 commits intomainfrom
dom/1201/binding-category-selection
Dec 18, 2025
Merged

Allow choice of binding category and renaming of bindings in specific categories (e.g., functions)#1319
jorisdral merged 8 commits intomainfrom
dom/1201/binding-category-selection

Conversation

@dschrempf
Copy link
Copy Markdown
Collaborator

@dschrempf dschrempf commented Nov 24, 2025

Allow user to control binding categories in a more fine-grained manner.

In particular, we will be able to include/exclude complete binding categories,
as well as rename declarations in term-level categories (e.g., functions,
function pointers, or globals).

We will have

data TermCategory =
    -- | Foreign import bindings with a @safe@ foreign import modifier.
    CSafe
    -- | Foreign import bindings with an @unsafe@ foreign import modifier.
  | CUnsafe
    -- | Pointers to functions; generally @unsafe@.
  | CFunPtr
    -- | Temporary category for bindings to global variables or constants.
  | CGlobal

data Category =
    -- | Types (top-level bindings).
    CType
  | CTerm TermCategory

-- | A category may contain types or terms.
type data CategoryLvl = LvlType | LvlTerm

-- | Include or exclude categories.
--
-- Possibly rename declarations in categories of 'Level' 'LvlTerm'. We only
-- allow renaming of 'LvlTerm' because for 'LvlType' we would also need to
-- rename the use sites, instances etc.
type Choice :: CategoryLvl -> Star
data Choice lvl where
  ExcludeCategory     :: Choice lvl
  IncludeTypeCategory :: Choice LvlType
  IncludeTermCategory :: RenameTerm -> Choice LvlTerm

Defaults

  • TH and literate modes: useSafeCategory.
  • preprocess mode: use all categories.

Remarks

Tasks

After meeting with Edsko:

  • We need to ensure that we do not rename unique symbols; we need some other changes before we can do so, and will pause this PR until then.

  • We want to extend the scope of the golden tests to check that we do not rename definition sites that have use sites.

  • The rename function needs to be discussed.

  • Fix Function pointer bindings should not have _ptr suffix #1262

  • Golden test case for Function pointer bindings should not have _ptr suffix #1262 <- We want to test the category choice renaming feature!

  • Check that empty modules are not created (@jorisdral ?) -> I think we should check this in a basic integration test (included in this PR), but handle the fixtures in a seprate task/PR.

@dschrempf dschrempf force-pushed the dom/1201/binding-category-selection branch from 0e0f83e to 48f7ed0 Compare November 24, 2025 12:21
@dschrempf dschrempf self-assigned this Nov 24, 2025
@dschrempf dschrempf linked an issue Nov 26, 2025 that may be closed by this pull request
@dschrempf dschrempf changed the title Binding category predicates Allow choice of binding category and renaming of bindings in specific categories (e.g., functions) Nov 26, 2025
@dschrempf dschrempf force-pushed the dom/1201/binding-category-selection branch 11 times, most recently from f344afa to dab8d20 Compare December 3, 2025 17:15
@dschrempf dschrempf force-pushed the dom/1201/binding-category-selection branch 3 times, most recently from 2e5185a to 35ef249 Compare December 9, 2025 11:06
@dschrempf dschrempf marked this pull request as ready for review December 9, 2025 14:15
@dschrempf dschrempf marked this pull request as draft December 9, 2025 14:16
@dschrempf dschrempf force-pushed the dom/1201/binding-category-selection branch 8 times, most recently from 7fbb182 to 08f0f8b Compare December 10, 2025 08:38
@dschrempf dschrempf marked this pull request as ready for review December 10, 2025 08:38
@dschrempf dschrempf force-pushed the dom/1201/binding-category-selection branch 5 times, most recently from 7e6b3a9 to 846f363 Compare December 18, 2025 07:27
Fixes #1262

- Allow choosing of binding categories, and renaming declarations of term-like
  categories

- Drop `_ptr` suffix from FunPtr and Global
  - Fixture changes (drop `_ptr`)
  - Fix manual (drop `_ptr`)

- Do not produce golden test file when output is empty
  - Remove empty golden files

Other changes:
- (Don't use) TypeData, which is only available since GHC 9.6
@dschrempf dschrempf force-pushed the dom/1201/binding-category-selection branch 2 times, most recently from e033109 to 6622876 Compare December 18, 2025 08:31
Copy link
Copy Markdown
Collaborator

@edsko edsko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, will be good to get this in :)

@dschrempf dschrempf force-pushed the dom/1201/binding-category-selection branch 3 times, most recently from 85f7f83 to 0449845 Compare December 18, 2025 11:47
@dschrempf dschrempf enabled auto-merge December 18, 2025 11:47
@dschrempf dschrempf force-pushed the dom/1201/binding-category-selection branch from 0449845 to 28c0c83 Compare December 18, 2025 11:59
@dschrempf dschrempf force-pushed the dom/1201/binding-category-selection branch from 28c0c83 to a7a0316 Compare December 18, 2025 12:12
@dschrempf dschrempf force-pushed the dom/1201/binding-category-selection branch from a7a0316 to 9323da1 Compare December 18, 2025 12:14
@dschrempf dschrempf added this pull request to the merge queue Dec 18, 2025
@jorisdral jorisdral removed this pull request from the merge queue due to a manual request Dec 18, 2025
@jorisdral jorisdral added this pull request to the merge queue Dec 18, 2025
Merged via the queue into main with commit 3383173 Dec 18, 2025
13 checks passed
@jorisdral jorisdral deleted the dom/1201/binding-category-selection branch December 18, 2025 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Function pointer bindings should not have _ptr suffix Unified choice of binding category between TH and CLI

3 participants